package com.gitee.wsl.data.input.viewmodel.scopes

import com.gitee.wsl.coroutines.Queued
import com.gitee.wsl.data.input.event.EventHandlerScope
import com.gitee.wsl.data.input.interceptor.BallastInterceptor
import com.gitee.wsl.data.input.viewmodel.actors.InputActor
import com.gitee.wsl.data.input.viewmodel.actors.InterceptorActor


internal class EventHandlerScopeImpl<Inputs : Any, Events : Any, State : Any>(
    private val inputActor: InputActor<Inputs, Events, State>,
    private val interceptorActor: InterceptorActor<Inputs, Events, State>,
) : EventHandlerScope<Inputs, Events, State> {

    override suspend fun postInput(input: Inputs) {
        inputActor.enqueueQueued(Queued.HandleInput(null, input), await = false)
    }

    override suspend fun <I : BallastInterceptor<*, *, *>> getInterceptor(key: BallastInterceptor.Key<I>): I {
        return interceptorActor.getInterceptor(key)
    }

    fun ensureUsedCorrectly() {
        // no-op
    }
}
